package qst.com.bacK.mapper;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;
import qst.com.bacK.pojo.entity.Choice;
import qst.com.bacK.pojo.entity.Question;
import qst.com.bacK.question.QuestionQueryParam;

import java.util.List;

/**
 * Author:   msh
 * Date:     2024/10/10 下午10:18
 * Description:
 */
public interface QuestionMapper {

    List<Question> find(QuestionQueryParam param);

    @Select("select * from choices where question_id = #{id}")
    List<Choice> findChoices(Integer id);

    @Select("select count(*) from questions where assessment_id = #{id}")
    int findCountByAssessment(int id);

    @Delete("delete from questions where id = #{id}")
    void deleteById(int id);

    @Select("select count(*) from question_dimension where dimension_id = #{id}")
    int findCountByDimension(int id);

    @Select("select * from questions where id = #{id}")
    Question findById(int id);

    @Select("select dimension_id from question_dimension where question_id = #{qid}")
    List<Integer> findDimension(int qid);

    @Delete("delete from question_dimension where question_id = #{qid}")
    void detachDimension(int qid);

    @Insert("insert into question_dimension(question_id, dimension_id) values(#{0}, #{1})")
    void attachDimension(int qid, int p);

    @Insert("insert into questions(title, hint, type, status, difficulty, assessment_id, user_id) " +
            "values(#{title}, #{hint}, #{type}, #{status}, #{difficulty}, #{assessmentId}, #{userId})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Question question);

    @Update("update questions set title = #{title}, hint = #{hint}, type = #{type}, status = #{status}, " +
            "difficulty = #{difficulty} where id = #{id}")
    void update(Question q);
}
